/**
 *
 */
package com.inmaytide.website.service.system.impl;

import com.google.common.collect.Sets;
import com.inmaytide.website.domain.entities.system.SysPermission;
import com.inmaytide.website.mapper.system.SysPermissionMapper;
import com.inmaytide.website.service.system.SysPermissionService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import java.util.Set;

/**
 * @author lomiao
 * @since May 14, 2016
 */
@Service
@Transactional(readOnly = true)
public class SysPermissionServiceImpl implements SysPermissionService {

    @Resource
    private SysPermissionMapper mapper;

    @Override
    public List<SysPermission> findPermissionsByRoleCodes(Collection<String> roleCodes) {
        return mapper.findPermissionCodesByRoleCodes(roleCodes);
    }

    @Override
    public Collection<String> findPermissionCodesByRoleCodes(Collection<String> roleCodes) {
        return findPermissionCodesByPermissions(findPermissionsByRoleCodes(roleCodes));
    }

    @Override
    public Collection<String> findPermissionCodesByPermissions(List<SysPermission> permissions) {
        Set<String> set = Sets.newHashSet();
        permissions.forEach(inst -> set.add(inst.getPermissionCode()));
        return set;
    }

}
